package com.frxuexi.park2209.notice

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.base.mvvm.BaseActivity
import com.frxuexi.park2209.R
import com.frxuexi.park2209.databinding.ActivityAddNoticeBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
class AddNoticeActivity : BaseActivity<ActivityAddNoticeBinding,NoticeViewModel>() {
    override fun initData() {
        lifecycleScope.launch {
            vm.addNoticeSuc.collect{
                if(it.isNotEmpty()){
                    ToastUtils.showLong(it)
                    finish()
                }
            }
        }
    }

    override fun initView() {
        binding.headerNoticeAdd.ivBack.setOnClickListener {
            finish()
        }

        binding.headerNoticeAdd.headerTitle.text="发布公告"

        binding.btnCommitNotice.setOnClickListener {
            val title = binding.etNoticeTitle.text.toString()
            val content = binding.etNoticeContent.text.toString()
            vm.addNotice(mapOf("noticeTitle" to title,"noticeValue" to content))
        }
    }

}